//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.未分类;

public class demo_1421 {
    public demo_1421() {
    }

    public int maxScore(String s) {
        int n = s.length();
        int sum = 0;

        for(int index = 1; index > 0 && index <= n - 1; index = s.indexOf(48, index) + 1) {
            String left = s.substring(0, index);
            String right = s.substring(index, n);
            int n1 = stringZeroNumber(left) + stringOneNumber(right);
            if (n1 > sum) {
                sum = n1;
            }
        }

        return sum;
    }

    public static int stringOneNumber(String str) {
        int num = 0;

        for(int index = str.indexOf(49); index != -1; index = str.indexOf(49, index + 1)) {
            ++num;
        }

        return num;
    }

    public static int stringZeroNumber(String str) {
        int num = 0;

        for(int index = str.indexOf(48); index != -1; index = str.indexOf(48, index + 1)) {
            ++num;
        }

        return num;
    }

    public int maxScore2(String S) {
        char[] s = S.toCharArray();
        int right1 = 0;

        for(char c : s) {
            right1 += c - 48;
        }

        int ans = 0;
        int left0 = 0;

        for(int i = 0; i < s.length - 1; ++i) {
            if (s[i] == '0') {
                ++left0;
            } else {
                --right1;
            }

            ans = Math.max(ans, left0 + right1);
        }

        return ans;
    }
}
